<?php

	$error = false;

	if(isset($_POST['sql_host']))
	{
			$_host = $_POST['sql_host'];
	} else {
			$_host = 'localhost';
	}
	
	$_db = null; $_user = null; $_pass = null;
	
	if(isset($_POST['sql_db'])) $_db = $_POST['sql_db'];
	if(isset($_POST['sql_user'])) $_user = $_POST['sql_user'];
	if(isset($_POST['sql_pass'])) $_pass = $_POST['sql_pass'];
	
	echo '
	<form action="?step=2&verify=true" method="post">
	<table border="0">
	<tr>
		<td>Mysql Server</td>
		<td><input type="text" name="sql_host" value="'.$_host.'" /></td>
	</tr>
	<tr>
		<td>Mysql Datenbank Name</td>
		<td><input type="text" name="sql_db" value="'.$_db.'" /></td>
	</tr>
	<tr>
		<td>Mysql Authentifizierungs Benutzername</td>
		<td><input type="text" name="sql_user" value="'.$_user.'" /></td>
	</tr>
	<tr>
		<td>Mysql Authentifizierungs Password</td>
		<td><input type="password" name="sql_pass" value="'.$_pass.'" /></td>
	</tr>
	</table>
	
	';
	
	
	if(isset($_POST['auth']))
	{
		$con = @mysql_connect($_POST['sql_host'], $_POST['sql_user'], $_POST['sql_pass']);
		if (!$con) {
			$error = true;
			$error_msg = mysql_error();
		}
		
		if($error === false)
		{
			$db_selected = @mysql_select_db($_POST['sql_db'], $con);
			if (!$db_selected) {
			   $error = true;
			   $error_msg = mysql_error();
			}
		}
		
		if($error === true)
		{
			echo '<p class="red">Fehler beim Verbinden zum MySql Server: '.$error_msg.'</p>';
			echo '<input type="submit" value="Verbindung Prf&uuml;fen" name="auth" />';
		} else {
			$_SESSION['sql_post'] = $_POST;
			echo '<p class="green">Verbindung wurde erfolgreich hergestellt.</p>';
			echo '<input type="button" onclick="location.href=\'?step=3\'" value="Weiter zu Schritt 3" />';
		}
		
	} else {
		echo '<input type="submit" value="Verbindung Pr&uuml;fen" name="auth" />';
	}
	
	echo "</form>";

?>